FILE(GLOB_RECURSE cc_sources *.cc)

add_library(buolacore SHARED ${cc_sources})

find_package(ZLIB REQUIRED)
find_package(DBus REQUIRED)
find_package(LibArchive REQUIRED)

find_library(LIB_M m)
find_library(LIB_UTIL util)
find_library(LIB_CURSES curses)
find_library(LIB_DL dl)
find_library(LIB_RT rt)
find_library(LIB_ICONV iconv)
find_library(LIB_INTL intl)
find_library(LIB_ICUUC icuuc)

set(LIBRARY_PLATFORM "")
if(LIB_RT)
    set(LIBRARY_PLATFORM ${LIBRARY_PLATFORM} ${LIB_RT})
endif()

if(LIB_ICONV)
    set(LIBRARY_PLATFORM ${LIBRARY_PLATFORM} ${LIB_ICONV})
endif()

if(LIB_INTL)
    set(LIBRARY_PLATFORM ${LIBRARY_PLATFORM} ${LIB_INTL})
endif()

if(LIB_DL)
    set(LIBRARY_PLATFORM ${LIBRARY_PLATFORM} ${LIB_DL})
endif()

if(LIB_UTIL)
    set(LIBRARY_PLATFORM ${LIBRARY_PLATFORM} ${LIB_UTIL})
endif()

include_directories(${BOOST_INCLUDE_DIR} ${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR})
target_link_libraries(buolacore ${LIBRARY_PLATFORM} ${LIB_M} ${Boost_LIBRARIES} ${LibArchive_LIBRARIES}
                    ${ZLIB_LIBRARIES} ${LIB_CURSES} ${LIB_ICUUC} ${DBUS_LIBRARIES})

if(BUOLA_PLATFORM_LINUX AND BUOLA_COMPILER_CLANG)
    target_link_libraries(buolacore /usr/lib/libstdc++.so.6)
endif()

set_target_properties(buolacore PROPERTIES VERSION ${GENERIC_LIB_VERSION}
                                        SOVERSION ${GENERIC_LIB_SOVERSION})

install(TARGETS buolacore DESTINATION ${LIB_INSTALL_DIR})
